{ open Parser } (* token types *)

rule token = parse
    [' ' '\t' '\r' '\n'] { token lexbuf } (* white space *)
    | "/*" { comment lexbuf } (* comment *)
    | "//" { singlecomment lexbuf }
    | '(' { LPAREN } 
    | ')' { RPAREN } 
    | '{' { LBRACE } 
    | '}' { RBRACE }
    | ';' { SEMI } 
    | ',' { COMMA }
    | '.' { DOT }
    | '+' { PLUS } 
    | '-' { MINUS }
    | '*' { TIMES } 
    | '/' { DIVIDE }
    | '%' { MOD }
    | '"' { QUOTATION}
    | "+=" { PLUSEQ }
    | "-=" { MINUSEQ }
    | "*=" { TIMESEQ }
    | "/=" { DIVIDEEQ }
    | "%=" { MODEQ }
    | '=' { ASSIGN } 
    | '!' { NOT }
    | "++" { PLUSPLUS }
    | "--" { MINUSMINUS }
    | "==" { EQ }
    | "!=" { NEQ } 
    | '<' { LT }
    | "<=" { LEQ } 
    | ">" { GT }
    | ">=" { GEQ } 
    | "&&" { AND }
    | "||" { OR }
    | "if" { IF } (* keyword *) 
    | "else" { ELSE } 
    | "for" { FOR }
    | "while" { WHILE } 
    | "return" { RETURN }
    | "void" { DATATYPE("void") }
    | "int" { DATATYPE("int") }
    | "string" { DATATYPE("string")}
    | "map" { DATATYPE("map") }
    | "player" { DATATYPE("player") }
    | "item" { DATATYPE("item") }
    | "point" { DATATYPE("point") }
    | ['0'-'9']+ as ints { INTEGER(int_of_string ints) } (* Integer *)
    | ['_']['a'-'z' 'A'-'Z' '_' '0'-'9']+ as gametype { GAMETYPE(gametype) }  (* typs for pacman  *)
    | ['a'-'z' 'A'-'Z' '0'-'9' '_']+ as id { ID(id) }
    | eof { EOF } (* End of file *)
    | _ as char { raise (Failure("illegal character: " ^ Char.escaped char)) }

    and comment = parse
    "*/" { token lexbuf } (* End of comment *)
    | _ { comment lexbuf } 
    
    and singlecomment = parse
    ['\r' '\n'] {token lexbuf } (* End of comment *)
    | _ {singlecomment lexbuf } 
